<template>
  <div class="container-v3">
<!--    <Row :gutter="16" class="tips-menu-v3">
      <Col span="6">
        <router-link to="">
          <div class="ac" @click.prevent="toMessage('separateservice', 1)">
            <div class="desc">
              全市通办<p>跨市区通办事项</p>
            </div>
            <div class="num">{{itemCategoryNum.separate || 0}}</div>
          </div>
        </router-link>
      </Col>
      <Col span="6">
        <router-link to="">
          <div class="nc" @click.prevent="toMessage('workbench', 2)">
            <div class="desc">
              待办事项<p>市民网络提报事项</p>
            </div>
            <div class="num">{{itemCategoryNum.remain_num || 0}}</div>
          </div>
        </router-link>
      </Col>
      <Col span="6">
        <router-link to="">
          <div class="ic" @click.prevent="toMessage('closingratelist', 0)">
            <div class="desc">
              统计报表<p>社区内工作统计</p>
            </div>
            <div class="num">{{itemCategoryNum.all_num || 0}}</div>
          </div>
        </router-link>
      </Col>
      <Col span="6">
        <router-link to="">
          <div class="gc" @click.prevent="toMessage('grid')">
            <div class="desc">
              社区网格<p>社区网格一张图</p>
            </div>
            <div class="num">{{itemCategoryNum.gridnum || 0}}</div>
          </div>
        </router-link>
      </Col>
    </Row>-->
    <Row :gutter="16" class="on-site-v3">
      <Col span="8">
        <Modal v-model="faceStatus" title="人脸识别" width="700"
               @on-ok="faceStatus=false" @on-cancel="faceStatus=false" :closable="false">
          <face-comparison :isPlay="faceStatus" @img-result="imgResult"></face-comparison>
        </Modal>
        <Modal v-model="user.show" title="个人信息" width="1008px" :loading="loading" :closable="false"
               @on-cancel="user.show=false">
          <Form :model="user" label-position="right" :label-width="100">
            <div class="wk1">
              <div class="img1 b_top_left">
                <img class="img2" :src="nophoto">
              </div>
              <div class="w90 b_top_left td1">姓名</div>
              <div class="w165 b_top_left ti">
                <!-- {{userInfo.name}} -->
                <input class="input1" v-model="userInfo.name" type="text "/>
              </div>
              <div class="w90 b_top_left td1">性别</div>
              <div class="w105 b_top_left ti">
                <!-- {{userInfo.sex}} -->
                <input class="input1" v-model="userInfo.sex" type="text "/>
              </div>
              <div class="w90 b_top_left td1">民族</div>
              <div class="w135 b_bottom ti">
                <!-- {{userInfo.folk}} -->
                <input class="input1" style="width: 90%;" v-model="userInfo.folk" type="text "/>
              </div>
              <div class="w90 b_bottom_right td1">身份证号</div>
              <div class="w165 b_bottom_right ti">{{userInfo.cardno}}</div>
              <div class="w90 b_top_left td1">房屋属性</div>
              <div class="w105 b_top_left ti">
                <select v-model="userInfo.house_condition" class="select1" style="width:90px;">
                  <option value="自住">自有</option>
                  <option value="租住">租住</option>
                </select>
              </div>
              <div class="w90 b_bottom_right td1">居住情况</div>
              <div class="w135 b_bottom ti">
                <select v-model="userInfo.living_condition" class="select1" style="width:115px;">
                  <option value="自住">自住</option>
                  <option value="租住">租住</option>
                  <option value="借住">借住</option>
                  <option value="其他">其他</option>
                </select>
              </div>
              <div class="w90 b_bottom_right td1">住址</div>
              <div class="w585 b_bottom ti">
                <!-- {{userInfo.address}} -->
                <input class="input1" v-model="userInfo.address" type="text "/>
              </div>
              <div class="w90 b_bottom_right td1">户籍地址</div>
              <div class="w585 b_bottom ti"><input class="input1" v-model="userInfo.domicile_address" type="text "/>
              </div>
              <div class="w135 b_bottom_right td1">手机号码</div>
              <div class="w190 b_bottom_right ti"><input class="input1" v-model="userInfo.mobile" type="text "/></div>
              <div class="w90 b_bottom_right td1">现住地址</div>
              <div class="w395 b_bottom ti"><input class="input1" v-model="userInfo.present_address" type="text "/>
              </div>
              <div class="w135 b_bottom_right td1">共同居住人员</div>
              <div class="w190 b_bottom_right ti">
                <select v-model="userInfo.co_resident" class="select1" style="width:170px;">
                  <option value="父母">父母</option>
                  <option value="配偶">配偶</option>
                  <option value="亲属">亲属</option>
                  <option value="其他">其他</option>
                  <option value="无">无</option>
                </select>
              </div>
              <div class="w105 b_bottom_right td1">银行卡收入情况</div>
              <div class="w115 b_bottom_right ti">
                <select v-model="userInfo.personal_income" class="select1" style="width:85px;">
                  <option value="5万以下">5万以下</option>
                  <option value="5-10万">5-10万</option>
                  <option value="10万以上">10万以上</option>
                  <option value="保密">保密</option>
                </select>
              </div>
              <div class="w95 b_bottom_right td1">工作单位</div>
              <div class="w170 b_bottom ti"><input class="input1" v-model="userInfo.work_unit" type="text "/></div>
              <div class="w135 b_bottom_right td1">文化程度</div>
              <div class="w90 b_bottom_right ti">
                <select v-model="userInfo.education" class="select1" style="width:70px;">
                  <option value="小学">小学</option>
                  <option value="初中">初中</option>
                  <option value="高中">高中</option>
                  <option value="大学">大学</option>
                  <option value="硕士研究生">硕士研究生</option>
                  <option value="博士研究生">博士研究生</option>
                  <option value="其他">其他</option>
                </select>
              </div>
              <div class="w100 b_bottom_right td1">婚姻状况</div>
              <div class="w65 b_bottom_right ti">
                <select v-model="userInfo.marriage" class="select1" style="width:55px;">
                  <option value="未婚">未婚</option>
                  <option value="已婚">已婚</option>
                  <option value="离异">离异</option>
                  <option value="丧偶">丧偶</option>
                  <option value="再婚">再婚</option>
                </select></div>
              <div class="w80 b_bottom_right td1">生育子女</div>
              <div class="w75 b_bottom_right ti">
                <select v-model="userInfo.child" class="select1" style="width:65px;">
                  <option value="无">无</option>
                  <option value="1个">1个</option>
                  <option value="2个">2个</option>
                  <option value="3个以上">3个以上</option>
                </select>
              </div>
              <div class="w95 b_bottom_right td1">政治面貌</div>
              <div class="w170 b_bottom ti">
                <select v-model="userInfo.political_outlook" class="select1" style="width:150px;">
                  <option value="群众">群众</option>
                  <option value="共产党员">共产党员</option>
                  <option value="共产主义青年团团员">共产主义青年团团员</option>
                  <option value="国民党革命委员会会员">国民党革命委员会会员</option>
                  <option value="民主同盟盟员">民主同盟盟员</option>
                  <option value="民主建国会会员">民主建国会会员</option>
                  <option value="民主促进会会员">民主促进会会员</option>
                  <option value="农工民主党党员">农工民主党党员</option>
                  <option value="致公党党员">致公党党员</option>
                  <option value="九三学社社员">九三学社社员</option>
                  <option value="台湾民主自治同盟盟员">台湾民主自治同盟盟员</option>
                  <option value="无党派民主人士">无党派民主人士</option>
                </select>
              </div>
              <div class="w135 b_bottom_right td1">兵役情况</div>
              <div class="w90 b_bottom_right ti">
                <select v-model="userInfo.military" class="select1" style="width:70px;">
                  <option value="是">是</option>
                  <option value="否">否</option>
                </select>
              </div>
              <div class="w100 b_bottom_right td1">职业</div>
              <div class="w220 b_bottom ti" style="width: 485px">
                <select v-model="userInfo.occupation" class="select1" style="width:200px;">
                  <option value="国家机关,党群组织,">国家机关,党群组织,企业</option>
                  <option value="企业,事业单位负责人">企业,事业单位负责人</option>
                  <option value="专业技术人员">专业技术人员</option>
                  <option value=">办事人员和有关人员">办事人员和有关人员</option>
                  <option value="商业,服务业人员">商业,服务业人员</option>
                  <option value="农,林,牧,渔,水利业生产人员">农,林,牧,渔,水利业生产人员</option>
                  <option value="生产,运输设备操作及有关人员">生产,运输设备操作及有关人员</option>
                  <option value="军人">军人</option>
                  <option value="退休">退休</option>
                  <option value="学生">学生</option>
                  <option value="学龄前">学龄前</option>
                  <option value="其他从业人员">其他从业人员</option>
                  <option value="无业人员">无业人员</option>
                </select>
              </div>
              <div class="w135 b_bottom_right td1">重点人群</div>
              <div class="w1701 ti" style="width: 675px">
                <Select v-model="groupData" multiple class="select1" style="width:662px;border: 1px solid white;">
                  <Option v-for="item in cityList" :value="item.value" :key="item.value"
                          style="border: 1px solid white;">{{ item.label }}
                  </Option>
                </Select>
              </div>
              <div class="w135 b_bottom_right td1">小区</div>
              <div class="w90 b_bottom_right ti">
                <select v-model="select11" class="select1" style="width:70px;">
                  <option :value="obj.id" v-for="obj in smallarealist" v-bind:key="obj.id">{{obj.title}}</option>
                </select>
              </div>
              <div class="w100 b_bottom_right td1">组</div>
              <div class="w220 b_bottom_right ti">
                <select v-model="select12" class="select1" style="width:200px;">
                  <option :value="obj.id" v-for="obj in grouplist" v-bind:key="obj.id">{{obj.title}}</option>
                </select>
              </div>
              <div class="w95 b_bottom_right td1">楼</div>
              <div class="w1701 ti">
                <select v-model="select13" class="select1" style="width:150px;">
                  <option :value="obj.id" v-for="obj in downlist" v-bind:key="obj.id">{{obj.title}}</option>
                </select>
              </div>
              <div class="w135 b_right td1">单元</div>
              <div class="w90 b_right ti">
                <select v-model="select14" class="select1" style="width:70px;">
                  <option :value="obj.id" v-for="obj in unitlist" v-bind:key="obj.id">{{obj.title}}</option>
                </select>
              </div>
              <div class="w100 b_right td1">层</div>
              <div class="w220 b_right ti">
                <select v-model="select15" class="select1" style="width:200px;">
                  <option :value="obj.id" v-for="obj in layerlist" v-bind:key="obj.id">{{obj.title}}</option>
                </select>
              </div>
              <div class="w95 b_right td1">户</div>
              <div class="w170 ti">
                <select v-model="userInfo.final_id" class="select1" style="width:150px;">
                  <option :value="obj.id" v-for="obj in householdlist" v-bind:key="obj.id">{{obj.title}}</option>
                </select>
              </div>
            </div>
            <br>
            <div class="div3">
              <P class="p1">备注：</P>
            </div>
            <br>
            <div class="div2">
              <textarea class="input3" v-model="userInfo.remarks" rows="5"/>
            </div>
          </Form>
          <div slot="footer">
            <Button type="text" size="large" @click="user.show=false">取消</Button>
            <Button type="primary" size="large" @click="saveUser">确定</Button>
          </div>
        </Modal>
        <Card class="user-info">
          <Row :gutter="10">
            <Col span="3">
              <div>
                <img :src="nophoto" style="height: 140px; width: 110px;" class="hd-img-responsive"/>
              </div>
            </Col>
            <Col span="5">
              <div>
                <p><span>姓名:</span> {{userInfo.name}}</p>
                <p style="margin-top: 6px"><span>性别:</span> {{userInfo.sex}}</p>
                <p style="margin-top: 6px"><span>民族:</span> {{userInfo.folk}}</p>
                <p style="margin-top: 6px"><span>出生日期:</span> {{userInfo.birthday}}</p>
                <p style="margin-top: 6px"><span>居住情况:</span> {{userInfo.living_condition}}</p>
              </div>
            </Col>
            <Col span="5">
              <div>
                <p><span>婚姻状况:</span> {{userInfo.marriage}}</p>
                <p><span>文化程度:</span> {{userInfo.education}}</p>
                <p><span>政治面貌:</span> {{userInfo.political_outlook}}</p>
                <p><span>兵役情况:</span> {{userInfo.military}}</p>
              </div>
            </Col>
            <Col span="5">
              <div>
                <p><span>职业:</span> {{userInfo.occupation}}</p>
                <p><span>联系方式:</span> {{userInfo.mobile}}</p>
                <p><span>共同居住人员:</span> {{userInfo.co_resident}}</p>
                <p><span>银行卡收入情况:</span> {{userInfo.personal_income}}</p>
              </div>
            </Col>
            <Col span="5">
              <div>
                <p style="margin-top: 5px"><span>身份证号:</span> {{userInfo.cardno}}</p>
                <p style="margin-top: 5px"><span>户籍地址:</span> {{userInfo.domicile_address}}</p>
                <p style="margin-top: 5px"><span>现住址:</span> {{userInfo.present_address}}</p>
                <!-- <p><span>备注:</span> {{userInfo.remarks}}</p>-->
              </div>
            </Col>
          </Row>
<!--          <Divider dashed/>-->
<!--          <Row :gutter="10">-->

<!--          </Row>-->
<!--          <Divider dashed/>-->
<!--          <Row :gutter="10">-->

<!--          </Row>-->
          <Divider dashed/>
          <Row :gutter="10" style="height: 65px;line-height: 65px">
            <Col span="3">
              <Button class="pad50_v3" type="primary" :loading="loading && !doItemData.loadingIndex" long
                      @click="withCard1">输入身份证号
              </Button>
            </Col>
            <Col span="3" offset="3">
              <Button class="pad50_v3" type="primary" :loading="loading && doItemData.loadingIndex" long
                      @click="withCard">有证办理
              </Button>
            </Col>
            <Modal v-model="modal" title="输入身份证号" width="500">
              <Row>
                <Col span="8" style="text-align: center;margin-top: 5px;">身份证号码:</Col>
                <Col span="12">
                  <Input v-model="cardId" placeholder=""></Input>
                </Col>
              </Row>
              <div slot="footer">
                <Button type="text" size="large" @click="modal = false">取消</Button>
                <Button type="primary" size="large" @click="ok111(cardId)">确定</Button>
              </div>
            </Modal>
            <Col span="3" offset="3">
              <Button class="pad50_v3" type="primary" long @click="withoutCard">人脸识别</Button>
            </Col>
            <Col span="3" offset="3">
              <Button class="pad50_v3" type="primary" :disabled="!doItemData.loadUserInfo" long @click="fillUserInfo">
                信息完善
              </Button>
            </Col>
          </Row>
        </Card>
      </Col>
    </Row>
    <Row>
      <Col span="24">
        <div class="opt-area-v3">
          <Tabs v-model="doItemData.searchLan" >
            <TabPane label="办理事项" name="name1" icon="md-list-box">
              <my-tabs :searchname="doItemData.text" :loaduser="doItemData.loadUserInfo"
                       :cardno="cardId" :usernname="this.userInfo.name"/>
            </TabPane>
<!--            <TabPane label="已办理事项" name="name2" icon="md-checkmark-circle">
              <Table height="400" :columns="columns1" :data="todolist">
                <template slot-scope="{ row }" slot="name">
                  <a style="color: #2D8cF0;" @click="orderInfo(row)">{{ row.name }}</a>
                </template>
              </Table>
            </TabPane>
            <TabPane label="可办理事项" name="name3" icon="md-checkmark-circle">
              <Table height="400" :columns="columns2" :data="todolist1"></Table>
            </TabPane>-->
          </Tabs>
<!--          <Input v-show="doItemData.searchLan == 'name1'" search placeholder="事项名称" class="search-input"
                 @on-change="searchList1" @on-search="searchList" v-model="doItemData.searchName"/>-->
        </div>
      </Col>
    </Row>
<!--    <Row :gutter="16" class="on-site-v3">
      <Col span="8">
        <Card class="notice-v3">
          <p slot="title">
            <Icon type="ios-film-outline"></Icon>
            通知公告
          </p>
          <a href="#" slot="extra" @click.prevent="toMessage('message')" class="notice-more">查看更多</a>
          <ul>
            <li v-for="(item, index) in noticeList" v-bind:key="index" @click.prevent="toMessage('message')">
              <Icon type="ios-arrow-forward"/>
              {{item.title}}
            </li>
          </ul>
        </Card>
      </Col>
      <Col span="16">
        <Card>
          <my-chart-bar style="height: 300px;" :value="barData" :run="run" text="近七日工作量"/>
        </Card>
      </Col>
    </Row>-->
  </div>
</template>

<script>
import './index.less'
import nophoto from '@/assets/images/nophoto.jpeg'
import { MyChartBar } from '_c/charts'
import FaceComparison from '_c/face-comparison'
import MyTabs from './myTabs'
import { upBase64 } from '@/api/common'
import {
  userinfo, userOrderList, orderWorkCountList, createuser, getCountForHome, getCountForHome1, yiBaoToken,
  releaseNoticeList, getsmallarealist, getgrouplist, getdownlist, updatePhotoByCardno, findDealableItem, date2str
} from '@/api/eventlist'
import { idcard, idcard2 } from '@/api/idcard'

export default {
  components: {
    MyChartBar,
    MyTabs,
    FaceComparison
  },
  data () {
    return {
      run: '1',
      readStatus: false,
      faceStatus: false,
      cardId: '',
      modal: false,
      userInfo: {
        final_id: '',
        ids: ''
      },
      nophoto,
      nophoto_bak: '',
      searchName: '',
      doItemData: { searchLan: 'name1', loadingIndex: true, loadUserInfo: false, searchName: '', text: '' },
      user: { show: false },
      loading: false,
      itemCategoryNum: {},
      visible: false,
      PhotoBmp: '',
      barData: {
        legend: ['接件量', '办结量'],
        xAxis: [],
        xAxisMap: {},
        seriesData: [
          { name: '接件量', data: [0, 0, 0, 0, 0, 0, 0], type: 'bar' },
          { name: '办结量', data: [0, 0, 0, 0, 0, 0, 0], type: 'bar' }
        ]
      },
      // 用户所有办理的事项列表
      columns1: [
        { title: '事项名称', slot: 'name' },
        { title: '办理进度', key: 'state', width: 100 },
        { title: '办理时间', key: 'create_time', width: 150 },
        { title: '办理地点', key: 'company_name', width: 200 }
      ],
      columns2: [
        { title: '事项名称', key: 'QL_NAME', width: 400 },
        { title: '级别', key: 'name', align: 'center', width: 150 },
        { title: '操作',
          key: 'action',
          align: 'center',
          render: (h, params) => {
            let temp = []
            temp.push(
              h('Button', {
                props: { type: 'success', size: 'small' },
                style: {},
                on: {
                  click: () => {
                    this.byrowidcardo(params)
                  }
                }
              }, '办理')
            )
            return h('div', temp)
          }
        }
      ],
      todolist: [],
      todolist1: [],
      noticeList: [],
      smallarealist: [], // 小区
      grouplist: [], // 组
      downlist: [], // 楼
      unitlist: [], // 单元
      layerlist: [], // 层
      householdlist: [], // 户
      select11: '',
      select12: '',
      select13: '',
      select14: '',
      select15: '',
      ids: '',
      idsArr: [],
      str1: '',
      str2: '',
      str3: '',
      str4: '',
      str5: '',
      cityList: [
        { value: '低保家庭', label: '低保家庭' },
        { value: '保障房家庭', label: '保障房家庭' },
        { value: '残疾人', label: '残疾人' },
        { value: '优抚对象', label: '优抚对象' },
        { value: '高龄老人', label: '高龄老人' },
        { value: '空巢老人', label: '空巢老人' },
        { value: '留守儿童', label: '留守儿童' },
        { value: '大病人群', label: '大病人群' },
        { value: '奖扶特扶人群', label: '奖扶特扶人群' },
        { value: '独生子女补助人群', label: '独生子女补助人群' },
        { value: '失业人员', label: '失业人员' },
        { value: '其他', label: '其他' }
      ],
      groupData: []
    }
  },
  methods: {
    // 要办理事项
    byrowidcardo (param) {
      let itemid = param.row.Row_ID
      if (param.row.org_code === '12210100738669464Y') {
        yiBaoToken({}).then(ret => {
          if (ret.data.data) {
            window.open(ret.data.data.url, '_blank')
          } else {
            this.$Notice.error({ title: '错误', desc: '获取链接失败，请重试' })
          }
        })
      } else if (param.row.org_code === '11210101000000FCJD') {
        this.$router.push({
          name: 'house_handinformation',
          params: { itemid: item.id, cardno: this.cardno, operation: '1' }
        })
      } else if (itemid === '11210101000000MZJD5212000330000') {
        this.$router.push({
          name: 'subsistenceapplication',
          params: { cardno: this.cardId, name: this.usernname, operation: '1' }
        })
      } else if (itemid === '11210101000000MZJD5212000328000') {
        this.$router.push({
          name: 'transregionalmigration',
          params: { cardno: this.cardId, operation: '1' }
        })
      } else if (itemid === '11210101000000MZJD5212000173000') {
        this.$router.push({
          name: 'stopinsurance',
          params: { cardno: this.cardId, operation: '1' }
        })
      } else {
        this.$router.push({
          name: 'handinformation',
          params: { itemid: itemid, cardno: this.cardId, operation: '1' }
        })
      }
    },
    // 可办理事项
    findDealableItem1 () {
      findDealableItem({ 'cardno': this.cardId }).then(ret => {
        this.todolist1 = ret.data.data
      })
    },
    findNoticeList () {
      releaseNoticeList().then(ret => {
        let length = ret.data.data.length > 7 ? 7 : ret.data.data.length
        for (var i = 0; i < length; i++) {
          this.noticeList.push(ret.data.data[i])
        }
      })
    },
    toMessage (path, indexs) {
      let router = this.$store.state.app.mainv3Nav
      router.forEach(element => {
        element.state = false
        if (element.path === '/' + path) {
          element.state = true
        }
      })
      this.$router.push({
        name: path,
        params: { tabindex: indexs }
      })
    },
    // 输入身份证号办理
    withCard1 () {
      this.readStatus = true
      this.cardId = ''
      this.doItemData.loadingIndex = false
      this.modal = true
    },
    // 刷身份证办理
    withCard () {
      this.readStatus = true
      let that = this
      this.doItemData.loadingIndex = true
      this.readIDCard(function (idcard) {
        that.cardId = idcard
        that.getUserInfo(idcard)
        that.userOrderList(idcard)
      })
    },
    ok111 (idcard) {
      if (this.isCardNo(idcard) !== false) {
        this.modal = false
        this.getUserInfo(idcard)
        this.userOrderList(idcard)
        this.findDealableItem1()
      }
    },
    // 刷脸办理
    withoutCard () {
      this.readStatus = true
      this.faceStatus = true
      console.log('刷脸办理')
    },
    // 完善用户信息
    fillUserInfo () {
      if (!this.readStatus) return
      this.user = { show: true }
    },
    searchList1 () {
      if (!this.doItemData.searchName) {
        this.searchList()
      }
    },
    // 办理事项列表的关键字搜索
    searchList () {
      this.doItemData.text = this.doItemData.searchName
    },
    // 刷读身份证后查询个人信息
    getUserInfo (cardno) {
      this.loading = true
      this.groupData = []
      this.userInfo.final_id = ''
      this.userInfo.ids = ''
      this.select11 = ''
      this.select12 = ''
      this.select13 = ''
      this.select14 = ''
      this.select15 = ''
      this.str2 = ''
      this.str3 = ''
      this.str4 = ''
      this.str5 = ''
      userinfo(cardno).then(res => {
        console.log('222222222222222222222222222222')
        console.log(res)
        this.loading = false
        if (res.data.data) {
          this.userInfo = res.data.data
          if (this.userInfo.focus_group) {
            this.groupData = this.userInfo.focus_group.split(',')
          }
          // 小区组楼地址回显
          // console.log(this.userInfo, '用户信息1')
          if (this.userInfo.ids !== undefined) {
            this.idsArr = this.userInfo.ids.split(',')
            this.str1 = this.idsArr[0]
            this.str2 = this.idsArr[1]
            this.str3 = this.idsArr[2]
            this.str4 = this.idsArr[3]
            this.str5 = this.idsArr[4]
            this.userInfo.final_id = this.idsArr[5]
            this.findGetsmallareaList(this.idsArr[0])
          }
          this.userInfo.refreshSelect = false
          if (res.data.data.photo) {
            this.nophoto = res.data.data.photo
          } else {
            // 查询后无用户头像，并且当前为刷身份证办理时，更新更新身份证头像
            if (this.doItemData.loadingIndex) {
              upBase64(this.PhotoBmp).then(data11 => {
                let param = {
                  cardno: cardno,
                  photo: data11.data.result
                }
                updatePhotoByCardno(param).then(res11 => {
                  if (res11.data.errcode === 0) {
                    console.log('更新头像成功')
                  } else {
                    console.log('更新头像失败')
                  }
                })
              })
            } else {
              this.nophoto = this.nophoto_bak
            }
          }
          this.doItemData.loadUserInfo = true
        } else {
          this.$Notice.error({ title: '新用户', desc: '请先完善用户的基础信息' })
          this.user = { show: true }
          if (!this.doItemData.loadingIndex) {
            this.PhotoBmp = ''
            this.userInfo = { cardno: cardno }
            this.nophoto = this.nophoto_bak || this.nophoto
          }
        }
      })
    },
    // 读取身份证信息
    readIDCard (callback) {
      let run_type = 1
      let interfaceResult =
          {
            0: { mean: '成功', message: '二代身份证读取成功！', type: 'success' },
            1: { mean: '端口打开失败', message: '未检测到二代身份证阅读器！', type: 'warning' },
            2: { mean: '数据传输超时', message: '未检测到二代身份证阅读器！', type: 'error' },
            10: { mean: '没有找到卡', message: '未读取到身份证，请重新刷卡！', type: 'warning' },
            11: { mean: '读卡操作失败', message: '未检测到二代身份证阅读器！', type: 'error' },
            20: { mean: '自检失败', message: '二代身份证读取失败！', type: 'error' },
            30: { mean: '其他错误', message: '二代身份证读取失败！', type: 'error' },
            40: { mean: '相片解码失败', message: '二代身份证读取失败！', type: 'error' },
            100: { mean: '超时', message: '未读取到身份证，请重新刷卡！', type: 'warning' },
            200: { mean: 'GetBase64PhotoData', message: '二代身份证读取失败！', type: 'error' }
          }
      let that = this
      this.loading = true
      if (run_type === 1) {
        idcard2().then(data => {
          this.loading = false
          let result = data.data
          if (result.code === 'SUCCESS') {
            that.userInfo = {
              name: result.result.Name,
              cardno: result.result.IDCode,
              address: result.result.Address,
              sex: result.result.Sex,
              folk: result.result.Nation
            }
            that.nophoto = 'data:image/png;base64,' + result.result.PhotoBmp
            that.PhotoBmp = result.result.PhotoBmp
            if (typeof callback === 'function') {
              callback(result.result.IDCode)
            }
          } else {
            that.$Message.warning(result.message)
          }
        }).catch(err => {
          that.loading = false
          that.$Message.warning('没有找到读卡设备')
          console.log(err, '错误信息')
        })
      } else {
        idcard().then(data => {
          this.loading = false
          let json = Object
          if (typeof data.data === 'object') {
            json = data.data
          } else {
            json = evil(data.data)
            let cardInfo = json.Certificate
            this.PhotoBmp = json.Certificate.Base64Photo
            that.userInfo = {
              name: cardInfo.Name,
              cardno: cardInfo.IDNumber,
              address: cardInfo.Address,
              sex: cardInfo.Sex,
              folk: cardInfo.Nation
            }
            that.nophoto = 'data:image/png;base64,' + json.Certificate.Base64Photo
            if (typeof callback === 'function') {
              callback(cardInfo.IDNumber)
            }
          }
          if (json.ret !== 0) {
            that.$Message.warning(interfaceResult[data.data.ret])
          }
        }).catch(err => {
          that.loading = false
          that.$Message.warning('没有找到读卡设备')
          console.log(err, '错误信息')
        })
      }
    },
    imgResult (idcard) {
      this.getUserInfo(idcard)
      this.userOrderList(idcard)
      this.faceStatus = false
    },
    orderInfo (obj) {
      if (obj.item_id === '11210101000000MZJD5212000330000') {
        this.$router.push({
          name: 'subsistenceapplication',
          params: { cardno: this.userInfo.cardno, code: obj.code, operation: '2' }
        })
      } else {
        this.$router.push({
          name: 'handinformation',
          params: {
            itemid: obj.item_id,
            cardno: this.userInfo.cardno,
            code: obj.code,
            path: 'mainv3',
            operation: '2'
          }
        })
      }
    },
    saveUser () {
      let that = this
      if (that.groupData) {
        that.userInfo.focus_group = this.groupData.join(',')
      }
      that.userInfo.ids = that.str1 + this.str2 + this.str3 + this.str4 + this.str5 + that.userInfo.final_id
      // console.log(this.PhotoBmp)
      if (this.PhotoBmp) {
        upBase64(this.PhotoBmp).then(data => {
          that.userInfo.photo = data.data.result
          that.uploadCardInfo(that.userInfo)
        })
      } else {
        that.userInfo.photo = null
        that.uploadCardInfo(that.userInfo)
      }
    },
    uploadCardInfo (userInfo) {
      createuser(userInfo).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({ title: '个人信息更新成功' })
          this.userInfo.id = res.data.data
          this.doItemData.loadUserInfo = true
          this.user.show = false
        } else {
          this.$Notice.error({ title: '个人信息更新失败', desc: res.data.errmsg })
        }
        this.findDealableItem1()
      })
    },
    // 用户订单列表
    userOrderList (cardno) {
      userOrderList(cardno).then(ret => {
        let data = []
        ret.data.data.forEach(function (item, index) {
          let json = {
            name: item.title,
            item_id: item.item_id + '',
            code: item.code,
            state: item.process_name,
            create_time: item.create_time,
            company_name: item.company_name
          }
          data.push(json)
        })
        this.todolist = data
      })
    },
    orderWorkCountList () {
      let dateKu = this.barData
      orderWorkCountList().then(ret => {
        let data = ret.data
        let dat1 = []
        let dat2 = []
        let forData = dateKu.xAxisMap
        if (data.errcode === 0) {
          for (let item1 in forData) {
            let num_j = 0
            let num_b = 0
            data.data.forEach(function (item, index) {
              if (item1 === item.day) {
                num_b = item.finish
                num_j = item.receive
              }
            })
            dat1[forData[item1]] = num_b
            dat2[forData[item1]] = num_j
          }
          dateKu.seriesData = [
            { name: '接件量', data: dat2, type: 'bar' },
            { name: '办结量', data: dat1, type: 'bar' }
          ]
          this.barData = dateKu
          this.run = '2'
        }
      })
    },
    // 事项分类统计，页面上边4个框内数值
    itemCategory () {
      this.itemCategoryNum = {}
      getCountForHome().then(ret => {
        this.itemCategoryNum.separate = ret.data.data.separate
        this.itemCategoryNum.all_num = ret.data.data.all_num
        this.itemCategoryNum.remain_num = ret.data.data.all_num - ret.data.data.finish_num
      })
      getCountForHome1().then(ret => {
        this.itemCategoryNum.gridnum = ret.data.data.num
      })
    },
    isCardNo (card) {
      // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
      var reg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/
      // var reg1 = /^1[45][0-9]{7}|([P|p|S|s]\d{7})|([S|s|G|g]\d{8})|([Gg|Tt|Ss|Ll|Qq|Dd|Aa|Ff]\d{8})|([H|h|M|m]\d{8，10})$/
      var reg1 = /^([a-zA-z]|[0-9]){5,17}$/
      if (reg.test(card) === false && reg1.test(card) === false) {
        const title = '错误提醒'
        const content = '<p>证件号码输入不合法</p>'
        this.$Modal.error({
          title: title,
          content: content,
          onOk: () => {
            console.log('失败')
          }
        })
        return false
      }
    },
    // 获取小区数据
    findGetsmallareaList (id) {
      getsmallarealist().then(ret => {
        if (ret.data.errcode === 0) {
          this.smallarealist = ret.data.data
          this.smallarealist.forEach((value, i) => {
            if (id === value.id.toString()) {
              this.select11 = value.id.toString()
              console.log(this.select11, '!!!!!14')
            }
          })
          return
        }
        this.$Notice.error({ title: '', desc: ret.data.errmsg })
      })
    },
    // 获取组数据
    findGetgroupList (id) {
      var param1 = {
        pid: id
      }
      getgrouplist(param1).then(res => {
        if (res.data.errcode === 0) {
          this.grouplist = res.data.data
          this.grouplist.forEach((value, i) => {
            if (this.idsArr[1] === value.id.toString()) {
              this.select12 = value.id.toString()
            }
          })
          return
        }
        this.$Notice.error({ title: '', desc: res.data.errmsg })
      })
    },
    // 获取楼数据
    findGetDownList (id) {
      var param1 = {
        'pid': id
      }
      getdownlist(param1).then(res => {
        if (res.data.errcode === 0) {
          this.downlist = res.data.data
          console.log(res, '楼')
          this.downlist.forEach((value, i) => {
            if (this.idsArr[2] === value.id.toString()) {
              this.select13 = value.id.toString()
            }
          })
          return
        }
        this.$Notice.error({ title: '', desc: res.data.errmsg })
      })
    },
    // 获取单元数据
    findGetUnitList (id) {
      var param1 = {
        'pid': id
      }
      getdownlist(param1).then(res => {
        if (res.data.errcode === 0) {
          this.unitlist = res.data.data
          console.log(res, '单元')
          this.unitlist.forEach((value, i) => {
            if (this.idsArr[3] === value.id.toString()) {
              this.select14 = value.id.toString()
            }
          })
          return
        }
        this.$Notice.error({ title: '', desc: res.data.errmsg })
      })
    },
    // 获取层数据
    findGetLayerList (id) {
      var param1 = {
        'pid': id
      }
      getdownlist(param1).then(res => {
        if (res.data.errcode === 0) {
          this.layerlist = res.data.data
          console.log(res, '层')
          this.layerlist.forEach((value, i) => {
            if (this.idsArr[4] === value.id.toString()) {
              this.select15 = value.id.toString()
            }
          })
          return
        }
        this.$Notice.error({ title: '', desc: res.data.errmsg })
      })
    },
    // 获取户数据
    findGetHouseholdList (id) {
      var param1 = {
        'pid': id
      }
      getdownlist(param1).then(res => {
        if (res.data.errcode === 0) {
          this.householdlist = res.data.data
          this.householdlist.forEach((value, i) => {
            if (this.idsArr[5] === value.id.toString()) {
              this.select16 = value.id.toString()
            }
          })
          return
        }
        this.$Notice.error({ title: '', desc: res.data.errmsg })
      })
    }
  },
  watch: {
    select11 (val) {
      this.str1 = val + ','
      // this.ids = this.str1 + ','
      this.findGetgroupList(val)
    },
    select12 (val) {
      this.str2 = val + ','
      // this.ids = this.ids + this.str2 + ','
      console.log('ids' + this.ids)
      this.findGetDownList(val)
    },
    select13 (val) {
      this.str3 = val + ','
      // this.ids = this.ids + this.str3 + ','
      console.log('ids' + this.ids)
      this.findGetUnitList(val)
    },
    select14 (val) {
      this.str4 = val + ','
      // this.ids = this.ids + this.str4 + ','
      console.log('ids' + this.ids)
      this.findGetLayerList(val)
    },
    select15 (val) {
      this.str5 = val + ','
      // this.ids = this.ids + this.str5 + ','
      console.log('ids' + this.ids)
      this.findGetHouseholdList(val)
    }
  },
  mounted () {
    this.groupData = []
    this.userInfo.ids = ''
    this.userInfo.final_id = ''
    this.str1 = ''
    this.str2 = ''
    this.str3 = ''
    this.str4 = ''
    this.str5 = ''
    let day = new Date()
    let barData = this.barData
    for (let i = 6; i >= 0; i--) {
      let temp = date2str(day)
      barData.xAxis[i] = temp.substring(5)
      barData.xAxisMap[temp] = i
      day.setDate(day.getDate() - 1)
    }
    // 默认备份无头像的图片，任何时候不修改备用图片
    this.nophoto_bak = this.nophoto
    this.barData = barData
    this.orderWorkCountList()
    this.itemCategory()
    this.findNoticeList()
    this.findGetsmallareaList()
  }
}
</script>
